﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BrokerBase.Lib.Policy;

namespace BrokerBase.Lib.Product.RateFactorConverter
{
    public abstract class AbstractRateFactorConverter : IRateFactorConverter
    {

        public virtual IRateFactor Owner { get; set; }

        public virtual bool IsMatch(string name)
        {

            if (string.IsNullOrEmpty(Alias.FirstOrDefault(p => p == name)))
                return false;
            else
                return true;

        }

        public abstract string[] Alias{get;}

        public virtual bool IsLadder { get { return false; } }

        public abstract bool IsToPropertiesEnable { get; }

        public abstract void ToProperties();

        public abstract bool IsPolicySelectedEnable { get; }

        public abstract void ToPolicySelected(IPolicy policy, string item);

        public virtual string GetItemByPolicy(IPolicy policy)
        {
            string value = policy.GetSelectedRateFactorItem(Owner.Name, Owner.Axis);

            string result = null;

            if (!string.IsNullOrEmpty(value))
            {
                result = value;
            }

            if(Owner.GroupItems.Count()==1)
            {
                result = Owner.GroupItems[0];
                policy.SetSettingLock(Owner.Name, true);
            }

            return result;
        }

        public virtual bool IsDisplay
        {
            get { return true ; }
        }

        public virtual bool IsFixedProperty { get { return false; } }
    }
}
